home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 44 / Amiga Format CD44 (1999-08-26)(Future Publishing)(GB)(Track 1 of 3)[!][issue 1999-10].iso / -in_the_mag- / basics / amos / idcmp.lha / OpenWindow7_IDCMP.AMOS / OpenWindow7_IDCMP.amosSourceCode
AMOS Source Code  |  1994-05-11  |  13KB  |  394 lines

  1. ' This is a little program that Opens up A window on the WB screen...
  2. ' and lets you hit the close gadget to quit... 
  3. ' I wrote it just because all the talk with Amos and Intuition, it is
  4. ' in no way complete support for windows.. its just a little example.. 
  5. '    
  6. ' note: Defines should be handled differently than the way I handled them  
  7. '       ...way inefficient... possibly a look up table could be used or just 
  8. '       have the programmer remember some numbers and or take away some
  9. '       functionality ?? I am not sure.. like I said I was just fooling
  10. '       around... Any suggestions... after we know how we are going to 
  11. '       handle defines and stuff I will write the routines to go through 
  12. '       the includes and convert...
  13. '
  14. ' note: You can only open one window with this because I have not added
  15. '       support to remove all memory allocated automatically... but you
  16. '       can remove the memory allocated for the newWindow struct yourself
  17. '       so then you can have anynumber of windows... you can use arrays
  18. '       or linked lists easily to accomplish this. 
  19. '  
  20. '       Also this program is pretty useless... just for example... but 
  21. '       it could be stripped down and then used as an De-Iconify or
  22. '       Amos to Front Button on the WorkBench Screen... just an idea 
  23. '       (better than saying.. oh ya you have to press LAmiga + A do
  24. '        get back to the program...) 
  25. '
  26. '  if you have any questions or whatever you can contact me at:
  27. '  
  28. '                   sikorsky@bode.ee.ualberta.ca 
  29. '
  30. '                   see ya later.... mike. 
  31. '
  32. '     .. oh ya this worked under KS1.3 & KS3.0 .... bye  
  33. '
  34. '************* Private ************* 
  35. 'Lvo's:
  36. '
  37. Global _LVOALLOCMEM,_LVOFREEMEM
  38. Global _LVOOPENLIB,_LVOCLOSELIB,_LVOOPENWINDOW,_LVOCLOSEWINDOW
  39. Global _LVOWAIT,_LVOGETMSG,_LVOREPLYMSG
  40. '
  41. 'Defines:
  42. '
  43. Global MEMF_ANY,MEMF_PUBLIC,MEMF_CHIP,MEMF_FAST,MEMF_CLEAR
  44.  
  45. Global NULL
  46. Global SMART_REFRESH,WBENCHSCREEN
  47.  
  48. Global WFLG_SIZEGADGET,WFLG_DRAGBAR,WFLG_DEPTHGADGET,WFLG_CLOSEGADGET,WFLG_SIZEBRIGHT,WFLG_SIZEBBOTTOM
  49. Global WFLG_REFRESHBITS,WFLG_SMART_REFRESH,WFLG_SIMPLE_REFRESH,WFLG_SUPER_BITMAP,WFLG_OTHER_REFRESH
  50. Global WFLG_BACKDROP,WFLG_REPORTMOUSE,WFLG_GIMMEZEROZERO,WFLG_BORDERLESS,WFLG_ACTIVATE
  51. Global WFLG_RMBTRAP,WFLG_NOCAREREFRESH,WFLG_NW_EXTENDED,WFLG_NEWLOOKMENUS
  52. Global WFLG_WINDOWACTIVE,WFLG_INREQUEST,WFLG_MENUSTATE,WFLG_WINDOWREFRESH,WFLG_WBENCHWINDOW
  53. Global WFLG_WINDOWTICKED,WFLG_VISITOR,WFLG_ZOOMED,WFLG_HASZOOM,_DEFAULTMOUSEQUE
  54.  
  55. Global IDCMP_CLOSEWINDOW,IDCMP_MOUSEBUTTONS
  56.  
  57. Global SELECTDOWN
  58. '
  59. 'Types:
  60. '
  61. Global WORD,UWORD,BYTE,UBYTE,LONG,ULONG,APTR
  62. '
  63. 'System:   
  64. '
  65. Global _NEWWINDOW_STRUCT_SIZE
  66. '
  67. '
  68. 'Shared: 
  69. '  _WINDOW_PTR --> _OPEN_WINDOW & _CLOSE_WINDOW
  70. '                  * Needed to de-allocate memory allocated for newwindow struct 
  71. '
  72. '
  73. '
  74.    _LVOALLOCMEM=-198 : _LVOFREEMEM=-210
  75.    _LVOOPENLIB=-552 : _LVOCLOSELIB=-414
  76.    _LVOOPENWINDOW=-204 : _LVOCLOSEWINDOW=-72
  77.  
  78.    _LVOWAIT=-318 : _LVOGETMSG=-372 : _LVOREPLYMSG=-378
  79.  
  80.    '/* mem requirements for AllocMem() */'  
  81.    'Add (or OR) them together to get 2 or more options
  82.    MEMF_ANY=0
  83.    MEMF_PUBLIC=1 : Rem ** means mean block can't move once alloced
  84.    MEMF_CHIP=2
  85.    MEMF_FAST=4
  86.    MEMF_CLEAR=65536
  87.    '
  88.    _WINDOW_DEFINES : Rem Set up the Window Defines....
  89.  
  90.    IDCMP_CLOSEWINDOW=$200
  91.    IDCMP_MOUSEBUTTONS=$8
  92.  
  93.    SELECTDOWN=$68
  94.  
  95.    'type sizes in bytes 
  96.    '
  97.    WORD=2 : UWORD=2 : BYTE=1 : UBYTE=1 : LONG=4 : ULONG=4 : APTR=4
  98.  
  99. '********** Public *********** 
  100.  
  101. MEM[0]
  102.  
  103.    Print "--> get ready " : Print " Press the close gadget of Window to Quit..." : Print "Hit a Key"
  104.  
  105.    Wait Key : Amos To Back 
  106.  
  107.    '  this will Open a Window That Responds to the "CloseGadget & Mouse Buttons" with Smart Refresh.... 
  108.    '
  109.    _OPEN_WINDOW[150,25,150,100,0,1,IDCMP_CLOSEWINDOW+IDCMP_MOUSEBUTTONS,WFLG_SMART_REFRESH+WFLG_CLOSEGADGET+WFLG_DEPTHGADGET+WFLG_DRAGBAR+WFLG_ACTIVATE+WFLG_SIZEGADGET,NULL,NULL,"Mike's Window",NULL,NULL,150,100,300,200,WBENCHSCREEN]
  110.  
  111.    WIN=Param : Rem Holds Address of the Window Struct returned (pointer)
  112.  
  113.    '
  114. _CLOSE_ME=0
  115.  
  116. While(_CLOSE_ME=0)
  117.  
  118.    MP_SIGBIT=Peek(Leek(WIN+86)+15) : Rem  Leek(WIN+86) --> Gives the Address of the MsgPort Struct
  119.                                      Rem  Leek(WIN+86)+15 --> Gives the Address of the field mp_SigBit for the MsgPort Struct 
  120.                                      Rem  Peek(Leek(WIN+86)+15) --> gets the mp_SigBit (ie. reads a byte from Address of the field mp_SigBit  
  121.  
  122.    Print MP_SIGBIT
  123.  
  124.    SIGNAL=1
  125.  
  126.    Rol.l MP_SIGBIT,SIGNAL : Rem  1 << window_ptr->UserPort->mp_SigBit
  127.  
  128.    Print SIGNAL
  129.  
  130.    Dreg(0)=SIGNAL
  131.    R=Execall(_LVOWAIT) : Rem *** Wait() for a Message *** 
  132.    Print R
  133.  
  134.    Print "Got the message"
  135.  
  136.    Areg(0)=Leek(WIN+86) : Rem  window_ptr->UserPort  
  137.    _INTUI_MSG=Execall(_LVOGETMSG) : Rem *** GetMsg() *** 
  138.  
  139.    While(_INTUI_MSG>0)
  140.  
  141.       CLASS=Leek(_INTUI_MSG+20)
  142.       CODE=Deek(_INTUI_MSG+24)
  143.  
  144.       Areg(1)=_INTUI_MSG
  145.       DUMMY=Execall(_LVOREPLYMSG) : Rem *** ReplyMsg() *** 
  146.  
  147.       If(CLASS=IDCMP_CLOSEWINDOW) : Rem ***Pressed the Close Gadget ***
  148.          _CLOSE_ME=1
  149.       End If 
  150.  
  151.       If(CLASS=IDCMP_MOUSEBUTTONS)
  152.  
  153.         If(CODE=SELECTDOWN)
  154.             Print "LMB Pressed"
  155.             Bell 50
  156.         End If 
  157.  
  158.  
  159.       End If 
  160.  
  161.       Areg(0)=Leek(WIN+86) : Rem  window_ptr->UserPort  
  162.       _INTUI_MSG=Execall(_LVOGETMSG) : Rem *** GetMsg() *** 
  163.  
  164.    Wend 
  165.  
  166.    'Amos To Front 
  167.  
  168.    'Wait Key  
  169.  
  170. Wend 
  171.  
  172.    _CLOSE_WINDOW[WIN]
  173.  
  174.    Amos To Front 
  175.  
  176. MEM[0]
  177.  
  178. Procedure _WINDOW_DEFINES
  179. '
  180.    NULL=0
  181.    SMART_REFRESH=0
  182.    WBENCHSCREEN=1
  183.  
  184. '/* --- Flags requested at OpenWindow() time by the application --------- */ 
  185. WFLG_SIZEGADGET=$1 : Rem  /* include sizing system-gadget? */ 
  186. WFLG_DRAGBAR=$2 : Rem /* include dragging system-gadget? */
  187. WFLG_DEPTHGADGET=$4 : Rem /* include depth arrangement gadget? */
  188. WFLG_CLOSEGADGET=$8 : Rem/* include close-box system-gadget? */
  189. WFLG_SIZEBRIGHT=$10 : Rem /* size gadget uses right border */
  190. WFLG_SIZEBBOTTOM=$20 : Rem /* size gadget uses bottom border */ 
  191. '/* --- refresh modes ------------------------------------------------------ */
  192. '/* combinations of the WFLG_REFRESHBITS select the refresh type */
  193. WFLG_REFRESHBITS=$C0
  194. WFLG_SMART_REFRESH=$0
  195. WFLG_SIMPLE_REFRESH=$40
  196. WFLG_SUPER_BITMAP=$80
  197. WFLG_OTHER_REFRESH=$C0
  198. WFLG_BACKDROP=$100 : Rem/* this is a backdrop window */ 
  199. WFLG_REPORTMOUSE=$200 : Rem/* to hear about every mouse move */
  200. WFLG_GIMMEZEROZERO=$400 : Rem/* a GimmeZeroZero window */
  201. WFLG_BORDERLESS=$800 : Rem/* to get a Window sans border */ 
  202. WFLG_ACTIVATE=$1000 : Rem/* when Window opens, it's Active */
  203. '/* --- Other User Flags --------------------------------------------------- */
  204. WFLG_RMBTRAP=$10000 : Rem/* Catch RMB events for your own */ 
  205. WFLG_NOCAREREFRESH=$20000 : Rem/* not to be bothered with REFRESH */ 
  206. '/* - V36 new Flags which the programmer may specify in NewWindow.Flags */ 
  207. WFLG_NW_EXTENDED=$40000 : Rem/* extension data provided */ 
  208.     Rem /* see struct ExtNewWindow */
  209. '/* - V39 new Flags which the programmer may specify in NewWindow.Flags */ 
  210. WFLG_NEWLOOKMENUS=$200000 : Rem/* window has NewLook menus */
  211.  
  212. '/* These flags are set only by Intuition.  YOU MAY NOT SET THEM YOURSELF! */
  213. WFLG_WINDOWACTIVE=$2000 : Rem/* this window is the active one */ 
  214. WFLG_INREQUEST=$4000 : Rem/* this window is in request mode */
  215. WFLG_MENUSTATE=$8000 : Rem/* Window is active with Menus on */
  216. WFLG_WINDOWREFRESH=$1000000 : Rem /* Window is currently refreshing */ 
  217. WFLG_WBENCHWINDOW=$2000000 : Rem /* WorkBench tool ONLY Window */ 
  218. WFLG_WINDOWTICKED=$4000000 : Rem /* only one timer tick at a time */
  219. '/* V36 and higher flags to be set only by Intuition: */ 
  220. WFLG_VISITOR=$8000000 : Rem/* visitor window  */ 
  221. WFLG_ZOOMED=$10000000 : Rem/* identifies "zoom state" */ 
  222. WFLG_HASZOOM=$20000000 : Rem/* window has a zoom gadget */
  223.  
  224. '/* --- Other Window Values ---------------------------------------------- */
  225. _DEFAULTMOUSEQUEUE=5 : Rem/* no more mouse messages */
  226.  
  227.  
  228.  
  229. '
  230. End Proc
  231.  
  232. '****
  233.  
  234. Procedure _OPEN_LIB[_LIB_NAME$,VER]
  235. '
  236.       _LIB_NAME$=_LIB_NAME$+Chr$(0)
  237.       Dreg(0)=VER
  238.       Areg(1)=Varptr(_LIB_NAME$)
  239.       BASE=Execall(_LVOOPENLIB)
  240. '
  241. End Proc[BASE]
  242. Procedure _CLOSE_LIB[BASE]
  243. '
  244.          Areg(1)=BASE
  245.          _RESULT=Execall(_LVOCLOSELIB)
  246. '
  247. End Proc
  248.  
  249. '****
  250. '
  251. Procedure _ALLOCMEM[BYTESIZE,REQUIREMENTS]
  252. '
  253.    Dreg(0)=BYTESIZE : Dreg(1)=REQUIREMENTS
  254.  
  255.    _PTR=Execall(_LVOALLOCMEM)
  256.  
  257. '
  258. End Proc[_PTR]
  259. Procedure _FREEMEM[MEMORY_PTR,BYTESIZE]
  260. '
  261.    Areg(1)=MEMORY_PTR : Dreg(0)=BYTESIZE
  262.  
  263.    RESULT=Execall(_LVOFREEMEM)
  264.  
  265. '
  266. End Proc[RESULT]
  267. '
  268. Procedure _OPEN_WINDOW[__X,__Y,__W,__H,__DPEN,__BPEN,__IDCMPFLAGS,__FLAGS,__FIRSTGAD,__CHECKMARK,__TITLE$,__SCREEN,__BITMAP,__MINW,__MINH,__MAXW,__MAXH,__TYPE]
  269. '
  270. Shared _WINDOW_PTR
  271.  
  272.    _STRUCT_NEWWINDOW[__X,__Y,__W,__H,__DPEN,__BPEN,__IDCMPFLAGS,__FLAGS,__FIRSTGAD,__CHECKMARK,__TITLE$,__SCREEN,__BITMAP,__MINW,__MINH,__MAXW,__MAXH,__TYPE]
  273.  
  274.    _WINDOW_PTR=Param
  275.  
  276.    Areg(0)=_WINDOW_PTR : WIN=Intcall(_LVOOPENWINDOW)
  277.  
  278.  
  279. '
  280. End Proc[WIN]
  281. Procedure _CLOSE_WINDOW[WIN]
  282. '
  283. Shared _WINDOW_PTR
  284.  
  285.    Areg(0)=WIN
  286.    R=Intcall(_LVOCLOSEWINDOW)
  287.  
  288.    _FREEMEM[_WINDOW_PTR,_NEWWINDOW_STRUCT_SIZE]
  289.  
  290. '
  291. End Proc[R]
  292. Procedure _STRUCT_NEWWINDOW[__X,__Y,__W,__H,__DPEN,__BPEN,__IDCMPFLAGS,__FLAGS,__FIRSTGAD,__CHECKMARK,__TITLE$,__SCREEN,__BITMAP,__MINW,__MINH,__MAXW,__MAXH,__TYPE]
  293. '
  294. 'struct NewWindow
  295. '{ 
  296. '    WORD LeftEdge, TopEdge;  /* screen dimensions of window */
  297. '    WORD Width, Height;   /* screen dimensions of window */ 
  298. '
  299. '    UBYTE DetailPen, BlockPen;  /* for bar/border/gadget rendering */ 
  300. '
  301. '    ULONG IDCMPFlags;   /* User-selected IDCMP flags */ 
  302. '
  303. '    ULONG Flags;   /* see Window struct for defines */
  304. '
  305. '    /* You supply a linked-list of Gadgets for your Window. 
  306. '     * This list DOES NOT include system Gadgets.  You get the standard 
  307. '     * system Window Gadgets by setting flag-bits in the variable Flags (see
  308. '     * the bit definitions under the Window structure definition) 
  309. '     */ 
  310. '    struct Gadget *FirstGadget; 
  311. '
  312. '    /* the CheckMark is a pointer to the imagery that will be used when 
  313. '     * rendering MenuItems of this Window that want to be checkmarked 
  314. '     * if this is equal to NULL, you'll get the default imagery 
  315. '     */ 
  316. '    struct Image *CheckMark;
  317. '
  318. '    UBYTE *Title;     /* the title text for this window */
  319. '
  320. '    /* the Screen pointer is used only if you've defined a CUSTOMSCREEN and 
  321. '     * want this Window to open in it. If so, you pass the address of the 
  322. '     * Custom Screen structure in this variable.  Otherwise, this variable
  323. '     * is ignored and doesn't have to be initialized. 
  324. '     */ 
  325. '    struct Screen *Screen;
  326. '
  327. '    /* WFLG_SUPER_BITMAP Window?  If so, put the address of your BitMap 
  328. '     * structure in this variable.  If not, this variable is ignored and
  329. '     * doesn't have to be initialized 
  330. '     */ 
  331. '    struct BitMap *BitMap;
  332. '
  333. '    /* the values describe the minimum and maximum sizes of your Windows. 
  334. '     * these matter only if you've chosen the WFLG_SIZEGADGET option, 
  335. '     * which means that you want to let the User to change the size of
  336. '     * this Window.  You describe the minimum and maximum sizes that the
  337. '     * Window can grow by setting these variables.  You can initialize
  338. '     * any one these to zero, which will mean that you want to duplicate
  339. '     * the setting for that dimension (if MinWidth == 0, MinWidth will be 
  340. '     * set to the opening Width of the Window). 
  341. '     * You can change these settings later using SetWindowLimits(). 
  342. '     * If you haven't asked for a SIZING Gadget, you don't have to
  343. '     * initialize any of these variables. 
  344. '     */ 
  345. '    WORD MinWidth, MinHeight;     /* minimums */
  346. '    UWORD MaxWidth, MaxHeight;      /* maximums */
  347. '
  348. '    /* the type variable describes the Screen in which you want this Window to
  349. '     * open.  The type value can either be CUSTOMSCREEN or one of the 
  350. '     * system standard Screen Types such as WBENCHSCREEN.  See the
  351. '     * type definitions under the Screen structure. 
  352. '     */ 
  353. '    UWORD Type; 
  354. '
  355. '};
  356. '
  357.    _NEWWINDOW_STRUCT_SIZE=(4*WORD+2*UBYTE+2*ULONG+5*APTR+2*WORD+2*UWORD+UWORD)
  358.  
  359.    _ALLOCMEM[_NEWWINDOW_STRUCT_SIZE,MEMF_ANY+MEMF_PUBLIC] : _PTR=Param
  360.  
  361.    If _PTR=0 Then Edit : Rem memexhaust 
  362.  
  363.    _APTR=_PTR : _TITLE$=_TITLE$+Chr$(0)
  364.  
  365. 'set up struct 
  366.  
  367.    Add _APTR,0 : Doke _APTR,__X
  368.    Add _APTR,WORD : Doke _APTR,__Y
  369.    Add _APTR,WORD : Doke _APTR,__W
  370.    Add _APTR,WORD : Doke _APTR,__H
  371.    Add _APTR,WORD : Poke _APTR,__DPEN
  372.    Add _APTR,UBYTE : Poke _APTR,__BPEN
  373.    Add _APTR,UBYTE : Loke _APTR,__IDCMPFLAGS
  374.    Add _APTR,ULONG : Loke _APTR,__FLAGS
  375.    Add _APTR,ULONG : Loke _APTR,__FIRSTGAD
  376.    Add _APTR,APTR : Loke _APTR,__CHECKMARK
  377.    Add _APTR,APTR : Loke _APTR,(Varptr(__TITLE$))
  378.    Add _APTR,APTR : Loke _APTR,__SCREEN
  379.    Add _APTR,APTR : Loke _APTR,__BITMAP
  380.    Add _APTR,APTR : Doke _APTR,__MINW
  381.    Add _APTR,WORD : Doke _APTR,__MINH
  382.    Add _APTR,WORD : Doke _APTR,__MAXW
  383.    Add _APTR,WORD : Doke _APTR,__MAXH
  384.    Add _APTR,WORD : Doke _APTR,__TYPE
  385.  
  386. '
  387. End Proc[_PTR]
  388. '
  389. Procedure MEM[DUMMY]
  390. '
  391.    Print Fast Free+Chip Free
  392.  
  393. '
  394. End Proc